define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/refund/index' + location.search,
                    add_url: 'order/refund/add',
                    // edit_url: 'order/refund/edit',
                    del_url: 'order/refund/del',
                    multi_url: 'order/refund/multi',
                    import_url: 'order/refund/import',
                    table: 'order_refund',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                showExport:false,//去掉导出
                // search:false,//去掉ID搜索
                // commonSearch:false,//去掉放大镜
                // showToggle:false,//去掉切换
                // showColumns:false,//去掉列
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'uid', title: __('Uid')},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        // {field: 'order_id', title: __('Order_id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'banc_id', title: __('Banc_id')},
                        {field: 'order_pay_price', title: __('Order_pay_price'), operate:'BETWEEN'},
                        {field: 'refund_desc', title: __('Refund_desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'refund_rate', title: __('Refund_rate')},
                        {field: 'rate_money', title: __('Rate_money'), operate:'BETWEEN'},
                        {field: 'refund_money', title: __('Refund_money'), operate:'BETWEEN'},
                        {field: 'operation_time', title: __('Operation_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-info btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'order/refund/pass',
                                    confirm: '确认通过此退款申请？',
                                    success: function (data, ret) {
                                        Layer.msg(ret.msg,{icon: 1,time: 2000});
                                        table.bootstrapTable('refresh',{url:'order/refund/index'});
                                        return false;
                                    },
                                    error:function (data, ret) {
                                        Layer.msg(ret.msg,{icon: 2,time: 3000});
                                        return false;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status==0){
                                            return true;
                                        }
                                        return false;
                                    }
                                },
                                {
                                    name: 'ajax',
                                    title: __('驳回'),
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    icon: 'fa fa-close',
                                    url: 'order/refund/refuse',
                                    confirm: '确认驳回此退款申请？',
                                    success: function (data, ret) {
                                        Layer.msg(ret.msg,{icon: 1,time: 2000});
                                        table.bootstrapTable('refresh',{url:'order/refund/index'});
                                        return false;
                                    },
                                    error:function (data, ret) {
                                        Layer.msg(ret.msg,{icon: 2,time: 3000});
                                        return false;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status==0){
                                            return true;
                                        }
                                        return false;
                                    }
                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
